package kpython.backend.ir.canon;

import kpython.backend.ir.tree.IRTreeVisitor;
import kpython.backend.ir.tree.Stmt;

public class OrFunction extends Stmt {

	public StringBuilder code = new StringBuilder();
	
	public OrFunction() {
		code.append("goto or_skip;\n");
		code.append("or:\n");		
		
		code.append("if(sp->locals[0].value.boolean == 0 || sp->locals[1].value.boolean == 0) \n");
		code.append("_rv->value.boolean = 0; \n");
		code.append("if(sp->locals[0].value.boolean == 1 || sp->locals[1].value.boolean == 1) \n");
		code.append("\t_rv->value.boolean = 1; \n");		
		code.append("_rv->type = v_boolean;\n");	
				
		code.append("goto redirector;\n");
		code.append("or_skip:\n");
	}
	
	@Override
	public Object accept(IRTreeVisitor visitor, Object data) {
		return visitor.visit(this, data);
	}

	@Override
	public void printTree(String tab) {		
		System.out.println(tab+this.getClass().getSimpleName());
		tab = tab+"\t";
		System.out.println(tab+"Label or");		
	}
	
	public String toString() {
		return this.getClass().getSimpleName();
	}

}
